package com.gemme.gemme.wode;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager.widget.ViewPager;

import com.gemme.gemme.BaseActivity;
import com.gemme.gemme.R;
import com.gemme.gemme.manager.DataManager;
import com.gemme.gemme.shequ.FmPagerAdapter;
import com.gemme.gemme.util.StrUtil;
import com.gemme.gemme.view.Topview;
import com.google.android.material.tabs.TabLayout;
import com.jaeger.library.StatusBarUtil;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;

//侧滑删除地址
public class PlatformMoneyNewActivity extends BaseActivity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_platform_money_new);
        initTop();
        initView();
    }


    @Override
    protected void onResume() {
        super.onResume();
        getData();
    }

    private TabLayout tabLayout;
    private ViewPager viewPager;
    private FmPagerAdapter pagerAdapter;
    private ArrayList<Fragment> fragments = new ArrayList<>();
    private String[] titles = new String[]{"收入","提现记录"};
    FragmentActivity act;
    TextView tv_assert;
    private void initView() {
        if(mContext instanceof FragmentActivity){
            act = (FragmentActivity)mContext;
            tabLayout = (TabLayout) findViewById(R.id.tablayout);
            viewPager = (ViewPager) findViewById(R.id.viewpager);
            TextView tv_tixian = findViewById(R.id.tv_tixian);
//            tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);

            tv_assert = findViewById(R.id.tv_assert);

           /* fragments.add(new GuanzhuFragment());
            fragments.add(new GuangchangFragment());*/

//            fragments.add(new GuanzhuFragment());
            fragments.add(new PlatFormShouRuFragment());
            fragments.add(new PlatFormTixianFragment());
            tabLayout.addTab(tabLayout.newTab());
            tabLayout.addTab(tabLayout.newTab());
            tabLayout.setupWithViewPager(viewPager,false);
            pagerAdapter = new FmPagerAdapter(fragments,act.getSupportFragmentManager());
            viewPager.setAdapter(pagerAdapter);
            for(int i=0;i<titles.length;i++){
                tabLayout.getTabAt(i).setText(titles[i]);
            }

            tv_tixian.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    try {
                        if(StrUtil.toLong(assets)  <= 0){
                            Toast.makeText(mContext, "没有提现额度", Toast.LENGTH_SHORT).show();
                            return;
                        }
                        Intent intent = new Intent(mContext, TixianActivity.class);
                        intent.putExtra("data",assets);
                        startActivity(intent);
                    }catch (Exception e){

                    }

                }
            });
        }



    }



    private void initTop() {
//        StatusBarUtil.setColor(this,getResources().getColor(R.color.white_color) );
        StatusBarUtil.setTransparent(this);
//        StatusBarUtil.setTranslucent(this,250);
        Topview topview = findViewById(R.id.topview);
        topview.setContentText("我的仙气值");
        topview.whiteTextColor();
    }
    String assets;
    private void getData() {
        String url = DataManager.BaseUrl+ "user/capital/getcoin";
        HashMap<String, String> headHashMap = new HashMap<>();
//        headHashMap.put(DataManager.AuthorizationKey,"Bearer 0af0e15c-0f2c-4b75-90f2-dc2c1236524d");
        headHashMap.put(DataManager.AuthorizationKey,DataManager.getToken(mContext));
        DataManager.toServer2(mContext, url, DataManager.GET_TYPE, "", headHashMap, new DataManager.GeResponse() {
            @Override
            public void onResponse(String response) {
                try {
                    assets = (new JSONObject(response)).getJSONObject("data").getString("assets");
                    tv_assert.setText(assets + "");
                    System.out.println("");
                }catch (Exception e){

                }
            }
        });
    }



}